import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
// import { baseConfig } from "vue-kst-auth";
import index from '../views/index.vue';
const routes: RouteRecordRaw[] = [
  {
    path: "/login",
    name: "登录",
    component: () => import("@/views/login.vue")
  },
  // {
  //   path: "/data-module",
  //   name: "dataModule",
  //   component: () => import("../views/dataModule/dataModule.vue")
  // },
  {
    path: '',
    redirect: '/home',
    component: index,
    children: [
      {
        path: "/home",
        name: "首页",
        component: () => import("../views/home/index.vue")
      },
      {
        path: "/device",
        name: "设备检测",
        component: () => import("../views/device/index.vue")
      },
      {
        path: "/monitoring",
        name: "监控视频",
        component: () => import("../views/monitoring/index.vue")
      },
      {
        path: "/timing",
        name: "时序图",
        component: () => import("../views/timing/index.vue")
      },
    ]
  }


];
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),//可传参数，配置base路径，例如'/app'
  routes
});
/** 路由拦截 */
router.beforeEach((to: any, _from: any, next: any) => {
  /* 路由发生变化修改页面meta */
  if (to.meta.content) {
    const head = document.getElementsByTagName("head");
    const meta = document.createElement("meta");
    meta.content = to.meta.content;
    head[0].appendChild(meta);
  }
  /* 路由发生变化修改页面title */
  if (to.name) {
    document.title = to.name;
  }
  next();
  // if (baseConfig.getLoginState() || /login/.test(to.path)) {
  //   next();
  // } else {
  //   next("/login");
  // }
});

export default router;
